﻿using System;
using System.IO;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Collections.Generic;
using System.ComponentModel;
using System.Windows.Forms;
using DevComponents.DotNetBar;
using DevComponents.AdvTree;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.DataSourcesGDB;
using ESRI.ArcGIS.DataSourcesRaster;
using PlanningGIS.Win.Controls;
using PlanningGIS.ArcGIS;
using System.Security.AccessControl;
using PlanningGIS.Util.IO;
using PlanningGIS.ArcGIS.Custom;
using PlanningGIS.Util.Log;

namespace PlanningGIS.Engine.Controls
{
    /// <summary>
    /// 作用：加载数据左边列表控件
    /// </summary>
    public partial class DirTree : AdvTree
    {        
        /// <summary>
        /// 构造函数
        /// </summary>
        public DirTree()
        {
            InitializeComponent();
            this.ExpandButtonType = eExpandButtonType.Rectangle;
            this.ExpandWidth = 14;
            this.ColorSchemeStyle = eColorSchemeStyle.Office2007;
            this.AfterExpand += new AdvTreeNodeEventHandler(DirTree_AfterExpand);
            this.AfterCollapse += new AdvTreeNodeEventHandler(DirTree_AfterCollapse);
            this.DoubleClick += new EventHandler(DirTree_DoubleClick);
        }

        /// <summary>
        /// 初始化目录树
        /// </summary>
        public void Initialize()
        {
            ImageList = ImageUtility.GetImageList();
            Nodes.Clear();
            AddDrives();
            AddSdeNode();
            if (Nodes.Count > 0)
                SelectedNode = Nodes[0];
        }

        /// <summary>
        /// 更新节点
        /// </summary>
        public void UpdateNode()
        {
            if (SelectedNode == null) return;
            Cursor = Cursors.WaitCursor;
            SelectedNode.Nodes.Clear();
            try
            {
                if (SelectedNode.Tag is string)
                {
                    AddDirectory(SelectedNode.Tag as string, SelectedNode.Nodes);
                    AddFile(SelectedNode.Tag as string, SelectedNode.Nodes);
                }
                else if (SelectedNode.Tag is DataBaseNode)
                {
                    AddDataset((SelectedNode.Tag as DataBaseNode), SelectedNode);
                }
                SelectedNode.Expand();
            }
            catch (Exception ex)
            {
                MsgHelper.ShowWarningMsgbox("刷新失败：" + ex.Message);
            }
            finally
            {
                Cursor = Cursors.Default;
            }
        }

        /// <summary>
        /// 设置当前选择的路径
        /// </summary>
        /// <param name="path">要设置的路径</param>
        public void SetSelectPath(string path)
        {
            string name = path.ToLower().Replace(AoHelper.SdePath.ToLower().Trim(), FrmOpenData.SDE_CONNECT + "\\");
            string[] ps = name.Split('\\');
            string p = "";
            NodeCollection tmpnodes = Nodes;
            for (int i = 0; i < ps.Length; i++)
            {
                if (ps[i].Trim() == "") continue;
                p += ps[i].Trim() + "\\";
                string fullname = p;
                if (p.Length > 3) fullname = p.Substring(0, p.Length - 1);                    
                Node[] ns = tmpnodes.Find(fullname.ToLower(), true);
                if (ns == null || ns.Length == 0) return;
                tmpnodes = ns[0].Nodes;
                if (ns[0].Nodes.Count > 0) continue;
                if (fullname.ToLower().EndsWith(".gdb") || fullname.ToLower().EndsWith(".mdb") || fullname.ToLower().EndsWith(".sde"))
                {
                    AddDataset(new DataBaseNode()
                    {
                        Path = fullname.Replace(FrmOpenData.SDE_CONNECT + "\\", AoHelper.SdePath)
                    }, ns[0]);
                }
                else if (fullname.ToLower().Contains(".gdb\\") || fullname.ToLower().Contains(".mdb\\") ||
                    fullname.ToLower().EndsWith(".dwg") || fullname.ToLower().EndsWith(".dgn") || fullname.ToLower().EndsWith(".dxf") ||
                    fullname.ToLower().EndsWith(".xls") || fullname.ToLower().EndsWith(".xlsx"))
                {
                    continue;
                }
                //else if ((new RasterWorkspaceFactory()).IsWorkspace(fullname)) continue;
                else
                {
                    AddDirectory(fullname, tmpnodes);
                    AddFile(fullname, tmpnodes);
                }
            }
            Node[] enode = Nodes.Find(name.ToLower(), true);
            if (enode == null || enode.Length == 0) return;
            this.SelectedNode = enode[0];
            this.SelectedNode.Expand();
        }
        
        /// <summary>
        /// 添加驱动和桌面
        /// </summary>
        private void AddDrives()
        {
            Node node = new Node();
            node.Text = "桌面";
            node.Tag = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
            node.Name = node.Tag.ToString().ToLower();
            node.Image = ImageUtility.GetImageList().Images[ImageUtility.desktop];
            node.ExpandVisibility = eNodeExpandVisibility.Visible;
            Nodes.Add(node);

            string[] paths = Directory.GetLogicalDrives();
            foreach (string subpath in paths)
            {
                node = new Node();
                node.Text = subpath;
                node.Name = subpath.ToLower();
                node.Tag = subpath.ToLower();
                DriveInfo driveinfo = new DriveInfo(subpath);
                switch (driveinfo.DriveType)
                {
                    case DriveType.CDRom:
                        node.Image = ImageUtility.GetImageList().Images[ImageUtility.dvd];
                        break;
                    case DriveType.Fixed:
                        node.Image = ImageUtility.GetImageList().Images[ImageUtility.drive];
                        break;
                    case DriveType.Network:
                        node.Image = ImageUtility.GetImageList().Images[ImageUtility.networkdrive];
                        break;
                    case DriveType.Removable:
                        node.Image = ImageUtility.GetImageList().Images[ImageUtility.removabledrive];
                        break;
                    default:
                        node.Image = ImageUtility.GetImageList().Images[ImageUtility.drive];
                        break;
                }
                Nodes.Add(node);
                node.ExpandVisibility = eNodeExpandVisibility.Visible;
            }
        }

        /// <summary>
        /// 添加Sde节点
        /// </summary>
        private void AddSdeNode()
        {
            if (!string.IsNullOrWhiteSpace(AoHelper.SdePath) && !Directory.Exists(AoHelper.SdePath))
                Directory.CreateDirectory(AoHelper.SdePath);
            Node node = new Node();
            node.Text = FrmOpenData.SDE_CONNECT;
            node.Name = FrmOpenData.SDE_CONNECT;
            node.Tag = AoHelper.SdePath;
            node.Image = ImageUtility.GetImageList().Images[ImageUtility.database];
            node.ExpandVisibility = eNodeExpandVisibility.Visible;
            Nodes.Add(node);

            ButtonItem btnAddConnect = new ButtonItem() { Name = "btnAddConnect", Text = "添加连接" };
            btnAddConnect.Click += new EventHandler(btnAddConnect_Click);
            
            ButtonItem btnDelAllConnect = new ButtonItem() { Name = "btnDelAllConnect", Text = "删除所有连接" };
            btnDelAllConnect.Click += new EventHandler(btnDelAllConnect_Click);
            
            ButtonItem btnConnectMenus = new ButtonItem() { Name = "btnConnectMenus", Text = "Sde连接", AutoExpandOnClick = true };
            btnConnectMenus.SubItems.AddRange(new DevComponents.DotNetBar.BaseItem[] { btnAddConnect, btnDelAllConnect });

            ContextMenuBar context = new DevComponents.DotNetBar.ContextMenuBar();
            context.Items.AddRange(new DevComponents.DotNetBar.BaseItem[] { btnConnectMenus });
            this.Parent.Controls.Add(context);
            node.ContextMenu = btnConnectMenus;
        }
        
        /// <summary>
        /// 删除所有sde连接
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void btnDelAllConnect_Click(object sender, EventArgs e)
        {
            if (this.SelectedNode == null) return;
            DialogResult dr = MsgHelper.ShowYesOrNoQueryMsgBox("确定要删除所有连接吗？");
            if (dr == DialogResult.No) return;
            try
            {
                string[] files = Directory.GetFiles(AoHelper.SdePath, "*.sde");
                foreach (string s in files)
                {
                    try
                    {
                        File.Delete(s);
                    }
                    catch(Exception ex)
                    {
                        LogHelper.WriteErrorText(ex);
                    }
                }
                this.SelectedNode.Nodes.Clear();
            }
            catch (Exception ex)
            {
                MsgHelper.ShowErrorMsgbox(ex.Message);
            }
        }

        /// <summary>
        /// 添加sde连接
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void btnAddConnect_Click(object sender, EventArgs e)
        {
            if (this.SelectedNode == null) return;
            try
            {
                FrmSdeConnect frm = new FrmSdeConnect();
                if (frm.ShowDialog() != DialogResult.OK)return;
                string fullname = frm.FullName;
                AddSdeFile(fullname, this.SelectedNode.Nodes);
            }
            catch(Exception ex)
            {
                LogHelper.WriteErrorText(ex);
            }
        }

        /// <summary>
        /// 添加目录节点
        /// </summary>
        /// <param name="path">文件目录</param>
        /// <param name="nodes">所在的节点集合</param>
        private void AddDirectory(string path, NodeCollection nodes)
        {
            if (string.IsNullOrEmpty(path) || path.StartsWith(FrmOpenData.SDE_CONNECT) || path.StartsWith(AoHelper.SdePath)) return;
            if (path.ToLower().Contains(".gdb\\") || path.ToLower().Contains(".mdb\\") || path.ToLower().Contains(".sde\\") ||
               path.ToLower().EndsWith(".dwg") || path.ToLower().EndsWith(".dgn") || path.ToLower().EndsWith(".dxf") ||
                 path.ToLower().EndsWith(".xls") || path.ToLower().EndsWith(".xlsx"))
                return;
            //添加该判断后只要目录中有图片，则目录就无法添加
            //if ((new RasterWorkspaceFactory()).IsWorkspace(path)) return;          
            
            if (!Directory.Exists(path)) return;
            string[] paths = Directory.GetDirectories(path);
            if (paths == null || paths.Length == 0) return;
            foreach (string subpath in paths)
            {
                DirectoryInfo di = new DirectoryInfo(subpath);
                Node node = new Node();
                node.Text = di.Name;
                node.Name = subpath.ToLower();
                node.Image = ImageUtility.GetImageList().Images[ImageUtility.folderclosed];
                node.Tag = subpath;
                try
                {
                    if (subpath.ToLower().EndsWith(PostFix.GDB))
                    {
                        if ((new FileGDBWorkspaceFactory()).IsWorkspace(subpath))
                        {
                            DataBaseNode dnode = new DataBaseNode();
                            dnode.WorkspaceType = zjgisWorkspaceType.gdb;
                            dnode.Path = subpath;
                            node.Tag = dnode;
                            node.Image = ImageUtility.GetImageList().Images[ImageUtility.gdb];
                        }
                    }
                    else
                    {
                        if (GeodatabaseHelper.IsGRID(subpath)) continue;
                    }
                    nodes.Add(node);
                    node.ExpandVisibility = eNodeExpandVisibility.Visible;
                }
                catch //目录可能没有访问权限
                {

                }
            }
        }

        /// <summary>
        /// 添加文件
        /// </summary>
        /// <param name="path">文件目录</param>
        /// <param name="nodes">所在的节点集合</param>
        private void AddFile(string path, NodeCollection nodes)
        {
            if (string.IsNullOrEmpty(path)) return;
            path = path.Replace(FrmOpenData.SDE_CONNECT, AoHelper.SdePath.Trim().Substring(0, AoHelper.SdePath.Trim().Length - 1));
            if (path.ToLower().Contains(".gdb\\") || path.ToLower().Contains(".mdb\\") || path.ToLower().Contains(".sde\\") ||
              path.ToLower().EndsWith(".dwg") || path.ToLower().EndsWith(".dgn") || path.ToLower().EndsWith(".dxf")
                || path.ToLower().EndsWith(".xls") || path.ToLower().EndsWith(".xlsx"))
                return;
            if (!Directory.Exists(path)) return;
            string[] fileNames = Directory.GetFiles(path);
            foreach (string fname in fileNames)
            {
                FileInfo fi = new FileInfo(fname);                
                Node node = new Node();
                node.Text = fi.Name;
                node.Name = fname.ToLower();                
                if (fi.Extension.Equals(PostFix.MDB,StringComparison.CurrentCultureIgnoreCase))
                {
                    DataBaseNode nd = new DataBaseNode();
                    nd.WorkspaceType = zjgisWorkspaceType.mdb;
                    nd.Path = fname;                    
                    nodes.Add(node);
                    node.ExpandVisibility = eNodeExpandVisibility.Visible;
                    node.Image = ImageUtility.GetImageList().Images[ImageUtility.mdb];
                    node.Tag = nd;
                }
                else if (fi.Extension.ToLower().EndsWith(PostFix.DGN) || fi.Extension.ToLower().EndsWith(PostFix.DWG) || fi.Extension.ToLower().EndsWith(PostFix.DXF))
                {
                    DatasetNode nd = new DatasetNode();
                    nd.WorkspaceType = zjgisWorkspaceType.cad;
                    nd.Path = fname;
                    nd.Name = fi.Name;
                    nodes.Add(node);
                    node.ExpandVisibility = eNodeExpandVisibility.Hidden;
                    if (fname.ToLower().EndsWith(PostFix.DGN))
                    {
                        node.Image = ImageUtility.GetImageList().Images[ImageUtility.dgn];
                    }
                    else
                    {
                        node.Image = ImageUtility.GetImageList().Images[ImageUtility.dwg];
                    }
                    node.Tag = nd;
                }
                else if (PostFix.XLS.Contains(fi.Extension.ToLower()))
                {
                    DataBaseNode nd = new DataBaseNode();
                    nd.WorkspaceType = zjgisWorkspaceType.xls;
                    nd.Path = fname;
                    nd.Name = fi.Name;
                    nodes.Add(node);
                    node.ExpandVisibility = eNodeExpandVisibility.Hidden;
                    node.Image = ImageUtility.GetImageList().Images[ImageUtility.tableset];
                    node.Tag = nd;
                }
                else if (fname.ToLower().EndsWith(PostFix.SDE))
                {
                    AddSdeFile(fname, nodes);
                }
            }
        }

        /// <summary>
        /// 添加sde文件
        /// </summary>
        /// <param name="file"></param>
        /// <param name="nodes"></param>
        private void AddSdeFile(string file, NodeCollection nodes)
        {
            DataBaseNode dataBaseNode = new DataBaseNode();
            dataBaseNode.WorkspaceType = zjgisWorkspaceType.sde;
            string fileName = System.IO.Path.GetFileName(file);
            dataBaseNode.Path = file;
            IWorkspaceFactory2 factory = new SdeWorkspaceFactory() as IWorkspaceFactory2;
            dataBaseNode.PropertySet = factory.ReadConnectionPropertiesFromFile(file);
            Node node = new Node();
            node.Text = fileName;
            node.Name = file.ToLower().Replace(AoHelper.SdePath.ToLower(), FrmOpenData.SDE_CONNECT + "\\");
            nodes.Add(node);
            node.ExpandVisibility = eNodeExpandVisibility.Hidden;   //sde连接默认不显示展开图标，只有双击连接成功后才装显示
            node.Image = ImageUtility.GetImageList().Images[ImageUtility.sdediscon];
            node.Tag = dataBaseNode;
            SetSdeMenu(node);
        }

        /// <summary>
        /// 
        /// </summary>
        private ButtonItem btnSdeMenu = null;
        
        /// <summary>
        /// Sde右键菜单
        /// </summary>
        /// <param name="node"></param>
        private void SetSdeMenu(Node node)
        {
            if (btnSdeMenu == null)
            {
                ButtonItem btnSdeProperty = new ButtonItem() { Name = "btnSdeProperty", Text = "连接属性" };
                btnSdeProperty.Click += new EventHandler(btnSdeProperty_Click);

                ButtonItem btnDelSde = new ButtonItem() { Name = "btnDelSde", Text = "删除连接" };
                btnDelSde.Click += new EventHandler(btnDelSde_Click);

                btnSdeMenu = new ButtonItem() { Name = "btnSdeMenu", Text = "Sde管理", AutoExpandOnClick = true };
                btnSdeMenu.SubItems.AddRange(new DevComponents.DotNetBar.BaseItem[] { btnSdeProperty, btnDelSde });

                ContextMenuBar context = new DevComponents.DotNetBar.ContextMenuBar();
                context.Items.AddRange(new DevComponents.DotNetBar.BaseItem[] { btnSdeMenu });
                this.Parent.Controls.Add(context);
            }
            node.ContextMenu = btnSdeMenu;
        }

        /// <summary>
        /// 删除sde连接
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void btnDelSde_Click(object sender, EventArgs e)
        {
            if (this.SelectedNode == null || this.SelectedNode.Tag == null) return;
            DialogResult dr = MsgHelper.ShowYesOrNoQueryMsgBox("确定要删除此连接吗？");
            if (dr == DialogResult.No) return;
            try
            {
                DataBaseNode dataBaseNode = this.SelectedNode.Tag as DataBaseNode;
                if (dataBaseNode == null) return;
                if (File.Exists(dataBaseNode.Path))
                {
                    try
                    {
                        File.Delete(dataBaseNode.Path);
                    }
                    catch 
                    {
                        
                    }
                    
                    //this.SelectedNode.TreeControl.SelectedNode = null;
                    //this.SelectedNode.TreeControl.SelectedNode = this.SelectedNode.Parent;
                    //this.SelectedNode.Parent.Nodes.Remove(this.SelectedNode);
                    this.SelectedNode.Remove();
                    this.SelectedNode = null;
                    MsgHelper.ShowInfomationMsgbox("删除成功。");
                }
            }
            catch (Exception ex)
            {
                MsgHelper.ShowErrorMsgbox(ex.Message);
            }
        }

        /// <summary>
        /// 设置sde连接属性
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void btnSdeProperty_Click(object sender, EventArgs e)
        {
            if (this.SelectedNode == null) return;
            try
            {
                DataBaseNode dbNode = this.SelectedNode.Tag as DataBaseNode;
                if (dbNode == null) return;
                FrmSdeConnect frm = new FrmSdeConnect();
                frm.FullName = dbNode.Path;
                frm.PropertyValue = dbNode.PropertySet;
                if (frm.ShowDialog() == DialogResult.OK)
                {
                    dbNode.PropertySet = frm.PropertyValue;
                    this.SelectedNode.Tag = dbNode;
                }
            }
            catch (Exception ex)
            {
                MsgHelper.ShowErrorMsgbox(ex.Message);
            }
        }

        /// <summary>
        /// 构建数据列表
        /// </summary>
        /// <param Name="dbNode"></param>
        /// <param Name="rootNode">根节点</param>
        /// <returns>是否创建成功</returns>
        private bool AddDataset(DataBaseNode dbNode, Node rootNode)
        {
            try
            {
                IWorkspace workspace = null;
                string path = dbNode.Path;
                NodeCollection nodes = rootNode.Nodes;
                zjgisWorkspaceType wstype = zjgisWorkspaceType.unknow;
                if (path.TrimEnd('\\').ToLower().EndsWith(PostFix.GDB))
                {
                    if ((new FileGDBWorkspaceFactory()).IsWorkspace(path))
                        wstype = zjgisWorkspaceType.gdb;
                }
                else if (path.TrimEnd('\\').ToLower().EndsWith(PostFix.MDB))
                {
                    if ((new AccessWorkspaceFactory()).IsWorkspace(path))
                        wstype = zjgisWorkspaceType.mdb;
                }
                else if (path.TrimEnd('\\').ToLower().EndsWith(PostFix.SDE))
                {
                    wstype = zjgisWorkspaceType.sde;
                }
                else
                {
                    return false;
                }
                dbNode.WorkspaceType = wstype;                
                workspace = dbNode.Open() as IWorkspace;
                string newname = dbNode.Path.ToLower().Replace(AoHelper.SdePath.ToLower(), FrmOpenData.SDE_CONNECT + "\\");
                if (workspace != null)
                {
                    IEnumDatasetName names = workspace.get_DatasetNames(esriDatasetType.esriDTFeatureDataset);
                    IDatasetName datasetName = names.Next();
                    while (datasetName != null)
                    {
                        DatasetNode datasetNode = new DatasetNode();
                        datasetNode.Name = datasetName.Name;
                        datasetNode.WorkspaceType = wstype;
                        datasetNode.Path = path + "\\" + datasetName.Name;
                        if (wstype == zjgisWorkspaceType.sde)
                        {
                            datasetNode.PropertySet = dbNode.PropertySet;
                        }
                        else
                        {
                            IPropertySet pPropertySet = new PropertySet();
                            pPropertySet.SetProperty("DATABASE", path);
                            datasetNode.PropertySet = pPropertySet;
                        }                        
                        Node node = new Node();
                        node.Text = datasetName.Name;
                        node.Name = (newname + "\\" + datasetName.Name).ToLower();
                        node.Image = ImageUtility.GetImageList().Images[ImageUtility.dataset];
                        node.Tag = datasetNode;
                        nodes.Add(node);
                        datasetName = names.Next();
                    }

                    names = workspace.get_DatasetNames(esriDatasetType.esriDTRasterCatalog);
                    datasetName = names.Next();
                    while (datasetName != null)
                    {
                        RasterCatalogNode rasterCatalogNode = new RasterCatalogNode();
                        rasterCatalogNode.Name = datasetName.Name;
                        rasterCatalogNode.WorkspaceType = wstype;
                        rasterCatalogNode.Path = path + "\\" + datasetName.Name;
                        if (wstype == zjgisWorkspaceType.sde)
                        {
                            rasterCatalogNode.PropertySet = dbNode.PropertySet;
                        }
                        else
                        {
                            IPropertySet pPropertySet = new PropertySet();
                            pPropertySet.SetProperty("DATABASE", path);
                            rasterCatalogNode.PropertySet = pPropertySet;
                        }                        
                        Node node = new Node();
                        node.Text = datasetName.Name;
                        node.Name = (newname + "\\" + datasetName.Name).ToLower();
                        node.Image = ImageUtility.GetImageList().Images[ImageUtility.rastercatalog];
                        node.Tag = rasterCatalogNode;
                        nodes.Add(node);
                        datasetName = names.Next();
                    }

                    if (dbNode.Path.EndsWith(".sde"))
                    {
                        rootNode.Image = ImageUtility.GetImageList().Images[ImageUtility.sdeconnect];
                        rootNode.ExpandVisibility = eNodeExpandVisibility.Visible;
                    }
                    return true;
                }
                else
                {
                    return false;
                }
            }
            catch (Exception ex)
            {
                MsgHelper.ShowErrorMsgbox(ex.Message);
                return false;
            }
        }
        
        /// <summary>
        /// 收缩后更改文件夹的状态
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DirTree_AfterCollapse(object sender, AdvTreeNodeEventArgs e)
        {
            if (e.Node == null) return;
            if (e.Node.Tag is string)
            {
                if (e.Node.Parent != null)  //非驱动即文件夹
                {
                    e.Node.Image = ImageUtility.GetImageList().Images[ImageUtility.folderclosed];
                }
            }
        }
        
        /// <summary>
        /// 展开
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DirTree_AfterExpand(object sender, AdvTreeNodeEventArgs e)
        {
            if (e.Node == null) return;
            //如果已经展开过，就不用再次去打开数据了，如果数据确实有所变化，提供右键刷新按钮
            if (e.Node.Nodes.Count > 0) return;
            if (e.Node.Tag is string)
            {
                AddDirectory(e.Node.Tag as string, e.Node.Nodes);
                AddFile(e.Node.Tag as string, e.Node.Nodes);                
            }
            else if (e.Node.Tag is DataBaseNode)
            {
                AddDataset((e.Node.Tag as DataBaseNode), e.Node);
            }
        }

        /// <summary>
        /// 双击目录节点
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DirTree_DoubleClick(object sender, EventArgs e)
        {
            if (this.SelectedNode == null) return;
            Node node = this.SelectedNode;
            if (node.Tag == null || !(node.Tag is DataBaseNode)) return;
            DataBaseNode dbNode = node.Tag as DataBaseNode;
            if (dbNode.WorkspaceType != zjgisWorkspaceType.sde) return;
            if (node.ExpandVisibility == eNodeExpandVisibility.Visible) return; //说明已经打开过
            Cursor = Cursors.WaitCursor;
            if (AddDataset(dbNode, node))
            {
                node.Expand();
            }
            Cursor = Cursors.Default;

        }

        /// <summary>
        /// F5刷新
        /// </summary>
        /// <param name="e"></param>
        protected override void OnKeyUp(KeyEventArgs e)
        {
            base.OnKeyUp(e);
            if (e.KeyCode == Keys.F5) UpdateNode(); //F5刷新
        }

    }
}
